/**
 *
 *
 */
package com.fw.timesheet.controller.master;

import java.util.List;

import org.zkoss.zk.ui.Component;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Textbox;

import com.fw.timesheet.common.util.ServiceLocator;
import com.fw.timesheet.controller.common.BaseController;
import com.fw.timesheet.model.Client;
import com.fw.timesheet.model.Project;
import com.fw.timesheet.model.ProjectTask;

/**
 * @author sigit <br>
 * @version 1.0 <br>
 *          Application : timesheet <br>
 *          Copyright (c) fastwire-group 2012 <br>
 * <br>
 */
public class ProjectTaskController extends BaseController {

	private Listbox projectTaskListbox, projectListbox,projectTaskListboxIn;
	private Textbox name;
	private Textbox country;
	private Project project;
	private ProjectTask projectTask,projectTaskMaster;

	@Override
	public void doAfterCompose(Component aWindow) throws Exception {
		// TODO Auto-generated method stub
		super.doAfterCompose(aWindow);
		loadAllProjectTask();
		loadAllProject();
		loadAllProjectTaskMaster();
	}

	private void loadAllProjectTask() {
		List<ProjectTask> projectTasks = ServiceLocator.getInstance()
				.getProjectTaskService().findAll();
		projectTaskListbox.getItems().clear();

		for (int i = 0; i < projectTasks.size(); i++) {
			projectTask = projectTasks.get(i);

			Listitem item = new Listitem();
			item.setValue(projectTask);

			project = ServiceLocator.getInstance().getProjectService()
					.findById(projectTask.getProjectId());

			Listcell cell = new Listcell(project.getName());
			cell.setParent(item);

			cell = new Listcell(projectTask.getName());
			cell.setParent(item);

			cell = new Listcell(projectTask.getStartDate().toString());
			cell.setParent(item);

			cell = new Listcell(projectTask.getStopDate().toString());
			cell.setParent(item);

			item.setParent(projectTaskListbox);
		}

	}

	private void loadAllProject() {
		List<Project> projects = ServiceLocator.getInstance()
				.getProjectService().findAll();
		projectListbox.getItems().clear();

		for (int i = 0; i < projects.size(); i++) {
			project = projects.get(i);

			Listitem item = new Listitem();
			item.setValue(project);

			Listcell cell = new Listcell(project.getName());
			cell.setParent(item);

			item.setParent(projectListbox);
		}

	}

	private void loadAllProjectTaskMaster() {
		List<ProjectTask> projectTasks= ServiceLocator.getInstance()
				.getProjectTaskService().findAll();
		projectTaskListboxIn.getItems().clear();

		for (int i = 0; i < projectTasks.size(); i++) {
			projectTaskMaster = projectTasks.get(i);

			Listitem item = new Listitem();
			item.setValue(projectTaskMaster);

			Listcell cell = new Listcell(projectTaskMaster.getName());
			cell.setParent(item);
			
			System.out.println("here >>"+projectTaskMaster.getName());

			item.setParent(projectTaskListboxIn);
		}

	}
}
